package com.lry;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
//https://www.zhihu.com/question/19787937
//https://xie.infoq.cn/article/e53cbcd0e723e3a6ce4be3b8c
//https://github.com/wuba/WPaxos
@Slf4j
public class Start {

    public static void main(String[] args) throws IOException, InterruptedException {
        Proposer proposer1 = new Proposer(2,1,3);

        Proposer proposer2 = new Proposer(0,2,7);


        Acceptor acceptor1 = new Acceptor("Acceptor1");
        Acceptor acceptor2 = new Acceptor("Acceptor2");
//        acceptor2.error = true;
        Acceptor acceptor3 = new Acceptor("Acceptor3");
//        acceptor3.error = true;

        proposer1.registerAcceptors(acceptor1,acceptor2,acceptor3);
        proposer2.registerAcceptors(acceptor1,acceptor2,acceptor3);

        CompletableFuture.runAsync(()->proposer1.prepareRequest());
        CompletableFuture.runAsync(()->proposer2.prepareRequest());

        Thread.sleep(1000);
        log.info("value1={},value2={},value3={},",acceptor1.value,acceptor2.value,acceptor3.value);
    }

}
